package controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import pojo.Department;
import pojo.DepartmentPage;
import service.DepartmentService;

/**
 * @author 郝雷蒙
 * @Description
 * @date 2020/12/8 20:07
 */
//注册为一个控制器
@Controller
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;

    private Integer pageSize = 4;

    @RequestMapping("/all_departments")
    public String getAllDepartments(Integer page, Model model){

        Integer pid = page==null? 1:page;

        DepartmentPage departmentPage = departmentService.getAllDepartments(pid,pageSize);

        model.addAttribute("departmentPage",departmentPage);

        return "all_departments";

    }
    @RequestMapping("goto_add")
    public String gotoAddDepartment(){return "add_department";}

    @RequestMapping("add_department")
    public String addOneDepartment(Department department,Model model){
        System.out.println(department);

        if (departmentService.addOneDepartment(department) > 0) {
            model.addAttribute("message", "用户注册成功");
        }
        else {
            model.addAttribute("message", "用户注册失败");
        }

        return "get_info";

    }

    }

